<template>
	<view class="content padding-top-01">
		<view class="font-size-26 text-right display-flex align-items flex-end"
			style="color: #FE6740; padding: 24rpx 24rpx 0;">
			<view @click="isflag = !isflag">
				{{!isflag?'管理':'完成'}}
			</view>
		</view>
		<view v-if="list.length == 0" class="display-flex flex-direction-column center align-items margin-top-120">
			<image :src="imgaeUrl('/static/home/kong.png')" style="width: 232rpx;height: 232rpx;" mode="widthFix">
			</image>
			<view class="font-size-28 margin-top-05 color-999">
				暂无足迹！
			</view>
		</view>
		<view class="margin-top-20 margin-top-20" v-for="item,index in list" :key="index" style="background: #FFFFFF;">
			<view style="padding: 24rpx;">
				<view class="display-flex align-items">
					<view v-if="isflag" @click.stop="allcheck(index)" class="margin-right-20">
						<uv-icon v-if="item.ischeck" name="checkmark-circle-fill" color="#FF8D1E" size="20"></uv-icon>

						<view v-else class="border-radius"
							style="border: 1rpx solid #333333; width: 18px;height: 18px;background: #FFFFFF;">

						</view>
					</view>
					<view class="font-size-28 font-weight-500">
						{{item.date}}
					</view>
				</view>
				<view class="item-view margin-top-20">
					<view v-for="goodsitem,goodsindex in item.list" :key="goodsindex"
						@click="navigateTo('/pages/Home/goodsDetails/goodsDetails?id=' + goodsitem.product_id)"
						class="position-relative display-flex flex-direction-column space-between">
						<view v-if="isflag" @click.stop="itemCheck(index,goodsindex)" class="position-absolute"
							style="top: 0;right: 0;">
							<uv-icon v-if="goodsitem.ischeck" name="checkmark-circle-fill" color="#FF8D1E"
								size="20"></uv-icon>

							<view v-else class="border-radius"
								style="border: 1rpx solid #333333; width: 18px;height: 18px;background: #FFFFFF;">

							</view>
						</view>
						<view class="">
							<image :src="goodsitem.thumb_img" style="width: 222rpx;height: 222rpx;"
								class="border-radius-12" mode="">
							</image>

							<view class="font-size-28 font-weight-500 webkit-line-clamp" style="-webkit-line-clamp: 2;">
								{{goodsitem.title}}
							</view>
						</view>
						<view class="">
							<view class="margin-top-10" style="color: #FF2E38;">
								<text class="font-size-24 font-weight-bold">￥</text>
								<text class=" font-size-36 font-weight-bold">{{goodsitem.sale_price}}</text>
							</view>
							<view class="display-flex margin-top-15 font-size-28 font-weight-500 align-items">

								<!-- <view style="width: 108rpx;font-size: 22rpx;height: 40rpx;"
																	class="label center-size-20  color-FFF">
																	
																</view> -->
								<view style="color: #FF2E38;font-size: 22rpx;border: none;background: #FFEEEA;"
									class="label1 center-size-20">
									{{ goodsitem.plan_type == 1?'定向高佣':'预估佣金'}}
									¥{{goodsitem.price}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<div class="kong"></div>
		<div v-if="isflag" class="kong"></div>

		<div v-if="isflag" class="kong safe-area-inset-bottom"></div>
		<view v-if="isflag" class="bottom " style="border-radius: 4rpx 4rpx 0 0;">
			<view class="padding-about-24 display-flex space-between align-items">
				<view class="margin-left-20 display-flex align-items" v-if="isflag" @click.stop="allischecks()">
					<uv-icon v-if="allischeck" name="checkmark-circle-fill" color="#FF8D1E" size="20"></uv-icon>
					<view v-else class="border-radius"
						style="border: 1rpx solid #333333; width: 18px;height: 18px;background: #FFFFFF;">
					</view>
					<view class="font-size-26 margin-left-20 ">
						全选
					</view>
					<!-- <view class="font-size-26 margin-left-20 ">
						选中{{}}个
					</view> -->
				</view>
				<view @click="clearFootPrint" style="width: 202rpx;height:70rpx;overflow: hidden;"
					class="button display-flex center align-items margin-left-20 color-FFF font-size-28 font-weight-500">
					删除
				</view>
			</view>
			<view class="safe-area-inset-bottom">

			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue';
	import {
		onLoad,
		onShow,
		onReady,
		onReachBottom
	} from '@dcloudio/uni-app';
	import {
		nativeUI,
		navigateTo,
		navigateBack,
		imgaeUrl
	} from '@/utils/index.js';
	import * as api from '@/request/app.js'; // 引入api 方法
	import local from '@/utils/localStorage.js'; //引入本地存储方法
	const pagingState = ref(false)
	const page = ref(1)
	const list = ref([]) //热门视频
	const isflag = ref(false)
	const allischeck = ref(false)
	onLoad(function(option) {
		getfootPrint()
	});
	onShow(function() {});

	function allischecks() {
		allischeck.value = !allischeck.value
		for (var i = 0; i < list.value.length; i++) {
			let item = list.value[i]
			item.ischeck = allischeck.value ? true : false
			for (var y = 0; y < item.list.length; y++) {
				let goodsItem = item.list[y]
				goodsItem.ischeck = allischeck.value ? true : false
			}
		}
	}

	function itemCheck(index, goodsIndex) {
		list.value[index].list[goodsIndex].ischeck = !list.value[index].list[goodsIndex].ischeck
		list.value[index].ischeck = list.value[index].list.every(item => item.ischeck)
	}

	function allcheck(index) {
		if (!list.value[index].ischeck) {
			list.value[index].ischeck = !list.value[index].ischeck
			list.value[index].list = list.value[index].list.map(item => {
				item.ischeck = true
				return item
			})
		} else {
			list.value[index].ischeck = !list.value[index].ischeck
			list.value[index].list = list.value[index].list.map(item => {
				item.ischeck = false
				return item
			})
		}

	}
	async function clearFootPrint() {
		let ids = []
		// .map(item=>{
		// 	let item.list.filter(goodItem=>goodItem.ischeck).map(goodItem=>goodItem.id)
		// })
		for (var i = 0; i < list.value.length; i++) {
			let item = list.value[i]
			for (var l = 0; l < item.list.length; l++) {
				let goodsItem = item.list[l]
				if (goodsItem.ischeck) {
					ids.push(goodsItem.id)
				}
			}
		}
		uni.showModal({
			title: '提示',
			content: '您确定要删除足迹吗？',
			success: async function(res) {
				console.log(ids);
				let object = {
					ids: ids.toString()
				}
				if (res.confirm) {
					const {
						code,
						data
					} = await api.clearFootPrint(object)
					if (code == 0) {
						getfootPrint()
					}
				} else if (res.cancel) {
					console.log('用户点击取消');
				}
			}
		});
	}
	/** 获取热门视频*/
	async function getfootPrint() {

		const {
			code,
			data
		} = await api.getfootPrint()
		if (code == 0) {
			list.value = data
		}
	}
	onReady(function() {});
	onReachBottom(function() {});
</script>

<style scoped lang="scss">
	.item-view {
		display: grid;
		grid-template-columns: repeat(3, 1fr);
		gap: 20rpx;
	}

	.label1 {
		// width: 68rpx;
		padding: 5rpx 10rpx;
		height: 32rpx;
		background: #FEEBEA;
		border-radius: 6rpx;

	}
</style>